package com.fantastic.web.controller.admin;

import com.fantastic.common.exception.enums.RespStatusInfo;
import com.fantastic.common.result.ResultData;
import com.fantastic.model.pojo.zjs.VarietySetMeal;
import com.fantastic.service.zjs.VarietySetMealService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: rxx
 * @since: 2024/6/1 18:35
 * @description: 菜品信息和套餐信息关联表控制器
 */
@RestController
@RequestMapping("/varietyMeal")
public class VarietySetMealControllerAdmin {

    @Resource
    private VarietySetMealService varietySetMealService;

    /**
     * 查询菜品信息和套餐信息关联表信息
     *
     * @param varietySetMeal
     * @param pageSize
     * @param pageNum
     * @return
     */
    @GetMapping("/listVarietyMeal")
    public ResultData listVarietyMeal(VarietySetMeal varietySetMeal,
                                      @RequestParam(name="page",
                                              defaultValue = "1") int pageNum,
                                      @RequestParam(name="limit",defaultValue = "9999999") int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<VarietySetMeal> meals = varietySetMealService.listVarietyMeal(varietySetMeal);
        PageInfo<VarietySetMeal> pageInfo = new PageInfo<>(meals);
        return new ResultData(RespStatusInfo.OK, pageInfo);
    }

    /**
     * 查询单个菜品信息和套餐信息关联表信息
     *
     * @param varietyMealId 关联表id
     * @return
     */
    @GetMapping("/getVarietyMeal")
    public ResultData getVarietyMeal(Integer varietyMealId) {
        return new ResultData(RespStatusInfo.OK, varietySetMealService.getVarietyMeal(varietyMealId));
    }

    /**
     * 添加菜品信息和套餐信息关联表信息
     *
     * @param varietySetMeal 套餐信息对象
     * @return
     */
    @PostMapping("/insertVarietyMeal")
    public ResultData insertVarietyMeal(VarietySetMeal varietySetMeal) {
        return new ResultData(RespStatusInfo.OK, varietySetMealService.insertVarietyMeal(varietySetMeal));
    }

    /**
     * 修改菜品信息和套餐信息关联表信息
     *
     * @param varietySetMeal
     * @return
     */
    @PostMapping("/updateVarietyMeal")
    public ResultData updateVarietyMeal(VarietySetMeal varietySetMeal) {
        return new ResultData(RespStatusInfo.OK, varietySetMealService.updateVarietyMeal(varietySetMeal));
    }

    /**
     * 删除菜品信息和套餐信息关联表信息
     *
     * @param varietyMealId
     * @return
     */
    @PostMapping("/deleteVarietyMeal")
    public ResultData deleteVarietyMeal(Integer varietyMealId) {
        return new ResultData(RespStatusInfo.OK, varietySetMealService.deleteVarietyMeal(varietyMealId));
    }
}
